package com.agent.vpsserver.common.utils.sign;

import org.apache.commons.codec.binary.Hex;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class SHA256Utils {
    /***
     *  SHA-256加密
     * @param str 待加密报文
     * @return
     * @throws NoSuchAlgorithmException
     * @throws UnsupportedEncodingException
     */
    public static String getSHA256Str(String str) throws NoSuchAlgorithmException, UnsupportedEncodingException{
        MessageDigest messageDigest;
        String encdeStr = "";
        messageDigest = MessageDigest.getInstance("SHA-256");
        byte[] hash = messageDigest.digest(str.getBytes("UTF-8"));
        encdeStr = Hex.encodeHexString(hash);
        return encdeStr;
    }
}